package com.itheima.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.DietDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Diet;
import com.itheima.service.DietService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service(interfaceClass = DietService.class)
@Transactional
public class DietServiceImpl implements DietService {
    @Autowired
    private DietDao dietDao;
    @Override
    public PageResult queryPage(QueryPageBean queryPageBean) {
        String queryString = queryPageBean.getQueryString();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        PageHelper.startPage(currentPage,pageSize);
        Page<Diet> diets = dietDao.selectByCondition(queryString);
        return new PageResult(diets.getTotal(),diets.getResult());
    }

    @Override
    public void add(Diet diet) {
        dietDao.add(diet);
    }
}
